package com.acme.domain.account;

import com.acme.exceptions.NotEnoughFundsException;

public abstract class AbstractAccount implements Account{

	protected int id;
	protected double balance;
	AbstractAccount(final double amount) {
		if ( amount < 0 ){
			throw new IllegalArgumentException("amount");
		}
		this.balance = amount;
	}

	public void setId(int id) {
		this.id = id;
	}

	public double getBalance() {
		return balance;
	}

	public void deposit(final double amount) {
		this.balance+=amount;
	}

	public abstract void withdraw(final double amount) throws NotEnoughFundsException;
	
	public int getId() {
		return id;
	}
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		} else if (obj == null){ 
			return false;
		} else if (!(obj instanceof Account)) {
			return false;
		} else {
			final Account acc = (Account) obj;
			if (this.id != acc.getId()) {
				return false;
			} else {
				return true;
			}
		}
	}

	public double maximumAmountToWithdraw() {
		return 0;
	}


	public String toString() {
		return "[ id:" + id + "; balance: " + this.balance + " ]"; 
	}
	
	public double decimalValue(){
		return Math.round(this.balance);
	}

	public int hashCode() { 
	    int hash = 1;
	    hash = hash * 31 + id;
	    return hash;
	}
	
}
